<?php
session_start();

if(!isset($_SESSION['userid']))//检查 userid 是否已经设置，如果没有设置，提示未登录并跳转首页
{
    echo "<script>alert('您尚未登录！')</script>";
    echo "<script>window.location.href='index.php'</script>";

}

$userid=$_SESSION['userid'];
include ('mysqli_connect.php');

?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>影视管理系统</title>
    <link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <style>
        body{
            width: 100%;
            height:auto;

        }
        #query{
            text-align: center;
        }
    </style>
</head>

<body>
<nav class="navbar navbar-default navbar-static-top" role="navigation">
    <div class="container-fluid">
        <div class="navbar-header">
            <a class="navbar-brand" href="#">我的影视库</a>
        </div>
        <div>
            <ul class="nav navbar-nav">


                <li><a href="user_index.php">主页</a></li>
                <li class="active"><a href="user_querymovie.php">影视查询</a></li>
                <li><a href="user_sheet.php">我的收藏</a></li>
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">个人信息<b class="caret"></b></a>

                    <ul class="dropdown-menu">
                        <li><a href="user_info.php">用户信息</a></li>
                        <li><a href="user_repass.php">修改密码</a></li>
                    </ul>
                </li>
                <li><a href="index.php">退出</a></li>

            </ul>
        </div>
    </div>
</nav>




<h1 style="text-align: center"><strong>全部影视信息</strong></h1>
<form  id="query" action="user_querymovie.php" method="POST">
    <div id="query">
        <label ><input  name="moviequery" type="text" placeholder="请输入影视名或影视ID" class="form-control"></label>
        <label ><input  name="movieclass" type="text" placeholder="请输入查询的分类" class="form-control"></label>
        <input type="submit" value="查询" class="btn btn-default">
    </div>
</form>

<table  width='100%' class="table table-hover">
    <tr>
        <th>影视ID</th>
        <th>导演</th>
        <th>分类</th>
        <th>地区</th>
        <th>上映时间</th>
        <th>语言</th>
        <th>时长</th>
        <th>中文名</th>
        <th>英文名</th>
        <th>评分</th>
<!--        <th>简介</th>-->
<!--        <th>评论</th>-->
<!--        <th>操作</th>-->
<!--        <th>操作</th>-->
        <th>详细信息</th>
    </tr>

<!--    这一段是套用的-->

    <?php

    if ($_SERVER["REQUEST_METHOD"] == "POST")
    {
        $gjc = $_POST["moviequery"];
        $movie_class=$_POST["movieclass"];
        if($movie_class!=''){
            $sql = "select * 
            from movie_information_table left outer join movie_classification_table using(movie_id) 
            WHERE classification like '%{$movie_class}%' or movie_intro like '%{$movie_class}%';";
            $res_temp=mysqli_query($dbc,$sql);
            while($row=mysqli_fetch_assoc($res_temp))
            {
                echo "<tr>";
                echo "<td>{$row['movie_id']}</td>";
                echo "<td>{$row['movie_director']}</td>";
                $sql_temp="SELECT `movie_classification_table`.`classification`,
                `movie_classification_table`.`movie_id`
                FROM `movie_classification_table`
                where movie_id='{$row['movie_id']}';";
                $res_temp=mysqli_query($dbc,$sql_temp);
                $classification='';
                while($row_temp=mysqli_fetch_assoc($res_temp))
                {
                $classification = $classification.(string)$row_temp['classification'];
                $classification = $classification."  ";
                }
                if($classification == ''){
                    echo "<td>无</td>";
                }
                else{
                    echo "<td>{$classification}</td>";
                }
                echo "<td>{$row['movie_regiou']}</td>";
                echo "<td>{$row['release_time']}</td>";
                echo "<td>{$row['movie_language']}</td>";
                echo "<td>{$row['movie_duration']}</td>";
                echo "<td>{$row['movie_Chinese_name']}</td>";
                echo "<td>{$row['movie_English_name']}</td>";
                echo "<td>{$row['movie_marking']}</td>";
                echo "<td><a href='user_movie_detail.php?id={$row['movie_id']}'>查看详情</a></td>";
                echo "</tr>";
            }
        }
        else 
        {
            $sql = "select * 
            from movie_information_table left outer join (select movie_id,marking_content from user_mark_table limit 0,1)as UM using(movie_id) 
            WHERE movie_id like '%{$gjc}%' or movie_Chinese_name like  '%{$gjc}%' or movie_English_name like '%{$gjc}%';";
        }
            
    }
    else{
        //$sql="select book_id,name,author,publish,ISBN,introduction,language,price,pubdate,book_info.class_id,class_name,pressmark,state
        //from book_info,class_info
        //where book_info.class_id=class_info.class_id ;";
        /*$sql="SELECT `movie_information_table`.`movie_id`,
            `movie_information_table`.`movie_director`,
            `movie_information_table`.`movie_regiou`,
            `movie_information_table`.`release_time`,
            `movie_information_table`.`movie_language`,
            `movie_information_table`.`movie_duration`,
            `movie_information_table`.`movie_Chinese_name`,
            `movie_information_table`.`movie_English_name`,
            `movie_information_table`.`movie_marking`,
            `movie_information_table`.`movie_intro`
            FROM `movie1`.`movie_information_table`;";*/
        $sql = "select * 
        from movie_information_table left outer join (select movie_id,marking_content from user_mark_table limit 0,1)as UM using(movie_id);";

    }


    $res=mysqli_query($dbc,$sql);
    //$row['movie_id']!= 0 是为了防止页面把默认的id为0的那个记录也显示出来了。
    while (($row = mysqli_fetch_assoc($res)) && $row['movie_id']!= 0){
        echo "<tr>";
        echo "<td>{$row['movie_id']}</td>";
        echo "<td>{$row['movie_director']}</td>";
        $sql_temp="SELECT `movie_classification_table`.`classification`,
        `movie_classification_table`.`movie_id`
        FROM `movie_classification_table`
        where movie_id='{$row['movie_id']}';";
        $res_temp=mysqli_query($dbc,$sql_temp);
        $classification='';
        while($row_temp=mysqli_fetch_assoc($res_temp))
        {
           $classification = $classification.(string)$row_temp['classification'];
           $classification = $classification."  ";
        }
        if($classification == ''){
            echo "<td>无</td>";
        }
        else{
            echo "<td>{$classification}</td>";
        }
        echo "<td>{$row['movie_regiou']}</td>";
        echo "<td>{$row['release_time']}</td>";
        echo "<td>{$row['movie_language']}</td>";
        echo "<td>{$row['movie_duration']}</td>";
        echo "<td>{$row['movie_Chinese_name']}</td>";
        echo "<td>{$row['movie_English_name']}</td>";
        echo "<td>{$row['movie_marking']}</td>";
        //echo "<td>{$row['class_name']}</td>";
        //echo "<td>{$row['pressmark']}</td>";
        //if($row['state']==1) echo "<td>在馆</td>"; else if($row['state']==0) echo "<td>已借出</td>";else  echo "<td>无状态信息</td>";
//        echo "<td><a href='admin_book_edit.php?id={$row['movie_id']}'>修改</a></td>";
//        echo "<td><a href='admin_book_del.php?id={$row['movie_id']}'>删除</a></td>";
        echo "<td><a href='user_movie_detail.php?id={$row['movie_id']}'>查看详情</a></td>";
        //if($row['state']==1)echo "<td><a href='admin_book_jiechu.php?id={$row['book_id']}'>借阅</a></td>";
        //if($row['state']==0)echo "<td><a href='admin_book_guihuan.php?id={$row['book_id']}'>归还</a></td>";
        echo "</tr>";
    };
    ?>
</table>
</body>
</html>

